﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interactivity;
using System.ComponentModel;

namespace OpenLightGroup.Common.Behaviors
{

    /// <summary>
    /// Automatically select all text in the associated TextBox when it gets focus.
    /// </summary>
    [Description("Automatically select all text in the associated TextBox when it gets focus.")]
    public class SelectTextOnFocusBehavior
        : Behavior<TextBox>

    {
        /// <summary>
        /// Overrides the base Behavior class method. This method wires up the event handler to the associated TextBox's GotFocus event.
        /// </summary>
        protected override void OnAttached()
        {
            base.OnAttached();
            this.AssociatedObject.GotFocus += new RoutedEventHandler(AssociatedObject_GotFocus);
           
        }


       /// <summary>
        /// Overrides the base Behavior class method. This method removes the event handler to the associated TextBox's GotFocus event.
        /// </summary>
        protected override void OnDetaching()
        {
            base.OnDetaching();

            this.AssociatedObject.GotFocus -= AssociatedObject_GotFocus;

        }

       private void AssociatedObject_GotFocus(object sender, RoutedEventArgs e)
        {

            this.AssociatedObject.SelectAll();

        }
    }
}
